package com.peopledelete.controller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.peopledelete.pojo.Pre;
import com.peopledelete.pojo.Preorigin;
import com.peopledelete.pojo.vo.preVo;
import com.peopledelete.service.PreService;
import com.peopledelete.service.PreoriginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @author cyt
 * @create 2020-05-13 15:57
 */

@RestController
public class preController {

    @Autowired
    PreService preService;

    @Autowired
    PreoriginService preoriginService;

    // 预测的数据
    @RequestMapping("/preDate")
    public ArrayList<preVo> preDate() {
        QueryWrapper<Pre> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id").last("limit 1");
        Pre pre = preService.getOne(wrapper);
        HashMap<Integer, Object> map = new HashMap<>();
        Integer amOne = pre.getAmOne();
        Integer amTwo = pre.getAmTwo();
        Integer pmOne = pre.getPmOne();
        Integer pmTwo = pre.getPmTwo();
        Integer night = pre.getNight();

        map.put(amOne, "十点之前");
        map.put(amTwo, "十点之后");
        map.put(pmOne, "两点之前");
        map.put(pmTwo, "两点到六点");
        map.put(night, "六点之后");

        preVo preVo1 = new preVo();
        preVo1.setName("'十点之前'").setValue(amOne);

        preVo preVo2 = new preVo();
        preVo2.setName("'十点之后'").setValue(amTwo);

        preVo preVo3 = new preVo();
        preVo3.setName("'两点之前'").setValue(pmOne);

        preVo preVo4 = new preVo();
        preVo4.setName("'两点到六点'").setValue(pmTwo);
        preVo preVo5 = new preVo();
        preVo5.setName("'六点之后'").setValue(night);
        ArrayList<preVo> preVo = new ArrayList<>();
        preVo.add(preVo1);
        preVo.add(preVo2);
        preVo.add(preVo3);
        preVo.add(preVo4);
        preVo.add(preVo5);
        return preVo;
    }

    // 预测和真实的对比数据
    @GetMapping("/preAndOrigin")
    public String preAndOrigin() {
        List<Preorigin> list = preoriginService.list(null);
        String s = JSON.toJSONStringWithDateFormat(list, "yyyy-MM-dd");
        return s;
    }
}
